# -*- coding: utf-8 -*-
# @Time    : 2019/1/8 17:28
# @Author  : zjj
# @Email   : 1933860854@qq.com
# @File    : jwt_payload_handler.py
# @Software: PyCharm
import uuid
from calendar import timegm
from datetime import datetime

from rest_framework_jwt.settings import api_settings

def jwt_payload_handler(user):
    payload = {
        'user_id': user.pk,
        'username': user.username,
        'user_role': user.role_id,
        'mobile': user.mobile,
    }

    if api_settings.JWT_ALLOW_REFRESH:
        payload['orig_iat'] = timegm(
            datetime.utcnow().utctimetuple()
        )

    # 接收方
    if api_settings.JWT_AUDIENCE is not None:
        payload['aud'] = api_settings.JWT_AUDIENCE

    # 签发者
    if api_settings.JWT_ISSUER is not None:
        payload['iss'] = api_settings.JWT_ISSUER

    return payload



